package com.hsw.habit.service.impl;

import com.hsw.habit.mapper.NoteGroupsMapper;
import com.hsw.habit.model.NoteGroups;
import com.hsw.habit.model.NoteGroups;
import com.hsw.habit.model.NoteGroupsExample;
import com.hsw.habit.model.bean.ListResponse;
import com.hsw.habit.service.GroupService;
import com.hsw.habit.service.NoteGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.logging.Logger;

@Service
public class NoteGroupServiceImpl implements NoteGroupService {
    @Resource
    private NoteGroupsMapper groupMapper;

    Logger logger = Logger.getLogger("groupService");

    @Override
    public NoteGroups selectGroupById(Integer id) {
        return groupMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<NoteGroups> selectGroupsByUserId(Integer id) {
        NoteGroupsExample noteGroupsExample = new NoteGroupsExample();
        NoteGroupsExample.Criteria criteria = noteGroupsExample.createCriteria();
        criteria.andUseridEqualTo(id);
        criteria.andIsdeletedEqualTo((short) 0);
        noteGroupsExample.setOrderByClause("created desc");
        return groupMapper.selectByExample(noteGroupsExample);
    }

    @Override
    public List<NoteGroups> selectByUserId(Integer userId) {
        NoteGroupsExample noteGroupsExample = new NoteGroupsExample();
        NoteGroupsExample.Criteria criteria = noteGroupsExample.createCriteria();
        criteria.andUseridEqualTo(userId);
        return groupMapper.selectByExample(noteGroupsExample);
    }

    @Override
    public boolean updateGroup(NoteGroups groups) {
        int res = groupMapper.updateByPrimaryKey(groups);
        return res == 1;
    }

    @Override
    public boolean deleteGroup(Integer id) {
        int res = groupMapper.softDeleteByPrimaryKey(id);
        return res == 1;
    }

    @Override
    public boolean insertGroup(NoteGroups groupModel) {
        int res = groupMapper.insert(groupModel);
        return res == 1;
    }
}
